<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Teacher\Controller;

/**
 * 后台首页控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class StudentController extends AdminController {

    /**
     * 后台首页
     * @author 麦当苗儿 <zuojiazi@vip.qq.com>
     */
    public function Reported(){
        if(UID){
            $Model   =   M('student_info');
            $map['class_id']=UID;
            $map['is_report']=(I('get.is_report')!='')?I('get.is_report'):array('neq',0);

            $id=I('get.id');
            if($id!='' && $id!=null){
                $map['introducer_id']=$id;
            }
            $name=I('get.name');
            if($name!='' && $name!=null){
                $map['name']=array('like','%'.$name.'%');
            }

            $ID_number=I('get.ID_number');
            if($ID_number!='' && $ID_number!=null){
                $map['ID_number']=array('like','%'.$ID_number.'%');
            }

            $list = $this->lists($Model,$map,'id desc');
            $this->assign('list', $list);
            $this->assign('is_report', I('get.is_report'));
            $this->meta_title = '学生信息';
            $this->display();
        } else {
            $this->redirect('Public/login');
        }
    }



    public function editInfo(){
        if(UID){
            $id   =   I('request.id');
            $is_report =   I('request.is_report');
            if(empty($id)){
                $this->error('请选择要操作的数据');
            }

            $map['id'] = $id;
            $data['is_report']=$is_report;

            $res=M('student_info')->where($map)->save($data);
            if($res) {
                $this->success('操作成功','',true);
            }else{
                $this->error('操作失败','',true);
            }
        }
    }


    function exportStudentInfo(){
        $map['class_id']=UID;
        $name=I('get.name');
        if($name!='' && $name!=null){
            $map['a.name']=array('like','%'.$name.'%');
        }
        $ID_number=I('get.ID_number');
        if($ID_number!='' && $ID_number!=null){
            $map['a.ID_number']=array('like','%'.$ID_number.'%');
        }

       $map['is_report']=(I('get.is_report')!='')?I('get.is_report'):array('neq',0);

        $list=M('student_info')
            ->alias('a')
            ->join('vo_major as b ON a.major=b.id')
            ->field('a.id,a.name,a.ID_number,a.sex,b.title,a.class_id,a.update_time,a.is_report')
            ->where($map)
            ->order('update_time desc')
            ->select();
        foreach ($list as $k=>&$vo){
            $vo['sex']=($vo['sex']==0)?'男':'女';
            $class=M('class')->where(array('id'=>$vo['class_id']))->field('title')->find();
            $vo['class_id']=$class['title'];
            $vo['update_time']=time_format($vo['update_time']);
            switch ($vo['is_report']){
                case 1:
                case 2:
                  $vo['is_report']="未报到";
                  break;
                case 3:
                  $vo['is_report']="已报到";
                  break;
            }
        }
    
        exportexcel($list,array('编号','姓名','身份证号','性别','专业','班级','提交报到时间','是否报到'),'班级管理信息');
    }


}
